//
//  RxWebViewController+LE.m
//  CreditAddressBookEE
//
//  Created by LE on 16/2/1.
//  Copyright © 2016年 Lee. All rights reserved.
//

#import "RxWebViewController+LE.h"

@implementation RxWebViewController (LE)

+ (instancetype)createWebViewControllerWithURL:(NSString *)url param:(NSDictionary *)param {
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:CYURLWithString(url)];
    if (param) {
        NSArray *keys = param.allKeys;
        NSMutableArray *attribute = [NSMutableArray array];
        for (NSString *key in keys) {
            NSString *body = [NSString stringWithFormat: @"%@=%@", key, param[key]];
            [attribute addObject:body];
//            if ([param[key] isKindOfClass:[NSString class]]) {
//                NSString *body = [NSString stringWithFormat: @"%@=%@", key, param[key]];
//                [attribute addObject:body];
//            } else {
//                NSParameterAssert(nil);
//            }
        }
        NSString *body = [attribute componentsJoinedByString:@"&"];
        body = [@"?" appendingString:body];
        [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
        [request setHTTPMethod:@"POST"];
        url = [url appendingString:body];
        RxWebViewController *web = [[RxWebViewController alloc] initWithRequest:request];
        return web;
    } else {
        RxWebViewController *web = [[RxWebViewController alloc] initWithUrl:[NSURL URLWithString:url]];
        return web;
    }
}
@end
